package org.dromara.system.service.impl;

import org.dromara.system.service.SysOssConfigService;
import org.dromara.system.pojo.entity.SysOssConfigDO;
import org.dromara.system.pojo.bo.SysOssConfigBO;
import org.dromara.system.pojo.qo.SysOssConfigQO;
import org.dromara.system.pojo.vo.SysOssConfigVO;
import org.dromara.system.mapper.SysOssConfigMapper;
import org.springframework.stereotype.Service;

import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.utils.BeanCopyUtils;

import java.util.List;

/**
 * 对象存储配置表 服务层实现。
 *
  * @author mkj
  * @since 2024-07-21
 */
@RequiredArgsConstructor
@Service
public class SysOssConfigServiceImpl  implements SysOssConfigService {

    private final SysOssConfigMapper sysOssConfigMapper;

    @Override
    public boolean add(SysOssConfigBO sysOssConfigBO) {
        SysOssConfigDO sysOssConfigDO = BeanCopyUtils.copy(sysOssConfigBO, SysOssConfigDO.class);
        return sysOssConfigMapper.insert(sysOssConfigDO) > 0;
    }

    @Override
    public boolean remove(Long id) {
        return sysOssConfigMapper.deleteById(id) > 0;
    }

    @Override
    public boolean update(SysOssConfigBO sysOssConfigBO) {
        SysOssConfigDO sysOssConfigDO = BeanCopyUtils.copy(sysOssConfigBO, SysOssConfigDO.class);
        return sysOssConfigMapper.update(sysOssConfigDO) > 0;
    }

    @Override
    public List<SysOssConfigVO> list(SysOssConfigQO sysOssConfigQO) {
        SysOssConfigDO sysOssConfigDO = BeanCopyUtils.copy(sysOssConfigQO, SysOssConfigDO.class);
        QueryWrapper queryWrapper = QueryWrapper.create(sysOssConfigDO);
        return sysOssConfigMapper.selectListByQueryAs(queryWrapper, SysOssConfigVO.class);
    }

    @Override
    public SysOssConfigVO getInfo(@PathVariable Long id) {
        SysOssConfigDO sysOssConfigDO = sysOssConfigMapper.selectOneById(id);
        if (sysOssConfigDO == null){
            return null;
        }
        return BeanCopyUtils.copy(sysOssConfigDO, SysOssConfigVO.class);
    }

    @Override
    public Page<SysOssConfigVO> page(SysOssConfigQO page) {
        return sysOssConfigMapper.paginateAs(page.getPageNumber(), page.getPageSize(), QueryWrapper.create(page), SysOssConfigVO.class);
    }

}

